package com.yiyue.graduate.controller;

import com.yiyue.graduate.pojo.Course;
import com.yiyue.graduate.pojo.FileData;
import com.yiyue.graduate.service.CourseService;
import com.yiyue.graduate.service.FileDataService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yiyuexiaofusheng
 * @date 2021/4/26
 */
@Controller
@RequestMapping("/course")
public class CourseController {

    @Resource
    CourseService courseService;
    @Resource
    FileDataService fileDataService;

    @GetMapping("/detail")
    public String detail(Long id, Model model){
        Course course = courseService.queryOneCourse(id);
        model.addAttribute("course",course);
        List<Course> topCourses = courseService.queryTopCourse();
        model.addAttribute("topCourse",topCourses);

        FileData fileData = fileDataService.getFileData(id);
        model.addAttribute("file",fileData);

        Course user = courseService.getUser(id);
        model.addAttribute("user",user);
        return "/course/detail";
    }

    @GetMapping("/allcourse")
    public String allCourse(Model model){
        List<Course> courses = courseService.queryAllCourse();
        model.addAttribute("courses",courses);
        return "/course/allcourse";
    }

    @GetMapping("/vedio")
    public String vedio(Long id,Model model){
        Course course = courseService.queryOneCourse(id);
        System.out.println(course);
        model.addAttribute("course",course);
        Course user = courseService.getUser(id);
        model.addAttribute("user",user);
        System.out.println(user);
        return "/course/vedio";
    }

    @GetMapping("/allfiledata")
    public String allFileData(Model model){
        List<FileData> fileData = fileDataService.queryAllFileData();
        model.addAttribute("files",fileData);
        return "/course/allfiledata";
    }

//    @GetMapping("/pay")
//    public String pay(){
//        return "pay";
//    }
//
//
    @GetMapping("/search")
    public String search(){
        return "/course/search";
    }
}
